package com.exp.bookhouse.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.exp.bookhouse.pojo.Permission;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface PermissionMapper extends BaseMapper<Permission> {

    @Select("select distinct  p.* from tb_user u, tb_user_role ur, tb_role_permission rp, tb_permission p where u.login_user = #{userName} and u.id = ur.user_id and ur.role_id = rp.role_id and rp.permission_id = p.id ")
    List<Permission> queryPermissionsByUserName(String userName);

    List<Permission> queryPermissionsByRoleId(Long id);

    @Delete("delete from tb_role_permission where permission_id  = #{id}")
    void deleteRolePermission(Long id);
}
